package ljt.music.module.blank;

import ljt.music.request.ApiService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @author jiangtao
 * @date 2017/12/21
 */

public class BlankFragmentModel {
    private static final String BASE_URL = "http://v.juhe.cn/";
    private Call<String> call;

    public void request(String maxBehotTime, Callback<String> callback) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
//                .addConverterFactory(ScalarsConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        ApiService apiService = retrofit.create(ApiService.class);
        call = apiService.getWenda(maxBehotTime);
        call.enqueue(callback);
    }

    public void interruptHttp() {
        if (call != null && !call.isCanceled()) {
            call.cancel();
        }
    }
}
